<?php
class AdminOrderTourController extends MyZend_Controller_Action {
	protected $_arrParam;
	
	protected $_actionMain;
	
	protected $_currentController;
	
	protected $_namespace;
	
	protected $_paginator = array(
			'itemCountPerPage' => 5,
			'pageRange' => 4
	);
	
	//protected $_errors = array();
	
	public function init() {
	
		$this->_arrParam          = $this->_request->getParams();
		$this->_currentController = '/' . $this->_arrParam['module']
		. '/' . $this->_arrParam['controller'];
	
		$this->_actionMain        = '/' . $this->_arrParam['module']
		. '/' . $this->_arrParam['controller'] . '/index';
	
		// filter session
		$this->_namespace = $this->_arrParam['module'] . '-' . $this->_arrParam['controller'];
		$ssFilter = new Zend_Session_Namespace($this->_namespace);
	
		if(empty($ssFilter->col)){
			$ssFilter->col   = 'o.id';
			$ssFilter->order = 'DESC';
		}

		$this->_arrParam['ssFilter']['col'] 		= $ssFilter->col;
		$this->_arrParam['ssFilter']['order'] 		= $ssFilter->order;
	
		// paginator
		$this->_paginator['currentPage'] = $this->_request->getParam('page',1);
		$this->_arrParam['paginator']    = $this->_paginator;
	
		// render to view
		$this->view->arrParam 		   = $this->_arrParam;
		$this->view->actionMain 	   = $this->_actionMain;
		$this->view->currentController = $this->_currentController;
	
		$this->_helper->layout()->disableLayout();
		$template_path = TEMPLATE_PATH . '/admin/main';
		$this->loadTemplate($template_path);
	}
	
	public function indexAction() {
		$this->view->Title = 'Bill Tour:: Manager :: List';
		$this->view->headTitle($this->view->Title, true);
		$tblOrderTour      = new Default_Model_OrderTour();
		$this->view->Items = $tblOrderTour->listItem($this->_arrParam, array('task' => 'admin-list'));
	
		$paginator = new MyZend_Paginator();
		$totalItem = $tblOrderTour->countItem($this->_arrParam);
		$this->view->paginator = $paginator->creatPaginator($totalItem, $this->_paginator);
			
	}
	
	// filter data post
	public function filterAction(){
		$ssFilter = new Zend_Session_Namespace($this->_namespace);
	
		// sort
		if($this->_arrParam['type'] == 'order') {
			$ssFilter->col   = $this->_arrParam['col'];
			$ssFilter->order = $this->_arrParam['by'];
		}
		$this->_redirect($this->_actionMain);
		$this->_helper->viewRenderer->setNoRender();
	}
	
	// change status
	public function statusAction() {
		$tblOrderTour  = new Default_Model_OrderTour();
		$tblOrderTour->changeStatus($this->_arrParam);
		$this->_redirect($this->_actionMain);
		$this->_helper->viewRenderer->setNoRender();
	}
	
	
	// delete item
	public function deleteAction() {
		$this->view->Title = 'Bill Tour:: Manager :: Delete';
		$this->view->headTitle($this->view->Title,true);
		if($this->_request->isPost()){
			$tblOrderTour  = new Default_Model_OrderTour();
			$tblOrderTour->deleteItem($this->_arrParam, array('task'=>'admin-delete'));
			$this->_redirect($this->_actionMain);
		}
	}
	
	// delete multi items
	public function multiDeleteAction() {
		if($this->_request->isPost()){
			$tblOrderTour  = new Default_Model_OrderTour();
			$tblOrderTour->deleteItem($this->_arrParam, array('task'=>'admin-multi-delete'));
			$this->_redirect($this->_actionMain);
		}
	}
	
	// view detail item
	public function infoAction() {
		$this->view->Title = 'Bill Tour:: Manager :: Information';
		$this->view->headTitle($this->view->Title,true);
		$tblOrderTour      = new Default_Model_OrderTour();
		$this->view->Item  = $tblOrderTour->getItem($this->_arrParam, array('task' => 'admin-info'));
	
	}
}